package de.koller.million.card.engine.report;

import de.koller.million.card.CNode;
import de.koller.million.card.engine.player.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Best extends CNode {

	private final List<Player> tmpPlayers = new ArrayList<>();
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
//		if( croot.getTime() % 1000 == 0 ) {
//			mostDamage();
//		}
	}
	
	public void mostDamage() {
		copyList();
		
		Collections.sort( tmpPlayers, new Comparator<Player> () {
			@Override public int compare( Player o1, Player o2 ) {
				int c = Double.compare( o1.stats.getDamage(), o2.stats.getDamage() ) * -1;
				if( c != 0 )
					return c;
				
				return Long.compare( o1.equipt.getLastEquipt(), o1.equipt.getLastEquipt() );
			}
		});
		
		Player b = tmpPlayers.get( 0 );
		//croot.news.publish( new TextNewsEntry( croot.getTime(), "[" + b + "] mit höchstem Schaden: " + Math.round( b.stats.getDamage() ) ) );
	
		//for( int i = 0; i < tmpPlayers.size(); i++ )
		//	tmpPlayers.get( i ).news.publish( new TextNewsEntry( croot.getTime(), "Platz " + (i+1) + " in meißtem Schaden." ) );
	}
	
	private void copyList() {
		tmpPlayers.clear();
		
		for( Player p : croot.engine.playerContainer.players )
			tmpPlayers.add( p );
	}
	
}
